#include "engine.h"
#include "internal_types.h"

#include <GL/glew.h>
#include <set>
using namespace std;

namespace HW
{
static set<TCamera> lCameras;

TCamera CreateCamera(TEntity parent)
{
	GameObject::_i_Camera newCamera;
	memset ( newCamera.clearColor.a , 0 , 4 );
	newCamera.clearMode = BUFFER_COLOR|BUFFER_DEPTH;
	memset ( newCamera.clipPlane.a , 0 , 4 );
	newCamera.farRange = 100.0f;
	newCamera.nearRange = 0.2f;
	newCamera.projMode = 1;
	newCamera.zoom = 1.0f;

	_i_World* currWorld = (_i_World*)(CurrentWorld());
	currWorld->camera.push_back ( newCamera );

	TCamera bpCam = (BP)(&currWorld->camera[currWorld->camera.size()-1]);
	lCameras.insert ( bpCam );
	return bpCam;
}

void CameraClearMode(TCamera camera, int mode)
{
	((GameObject::_i_Camera*)(camera)) -> clearMode = mode;
}

void CameraClearColor(TCamera camera, const TVec4 &color)
{
	((GameObject::_i_Camera*)(camera)) -> clearColor = color;
}

void CameraRange(TCamera camera, flt nearrange, flt farrange)
{
	((GameObject::_i_Camera*)(camera)) -> nearRange = nearrange;
	((GameObject::_i_Camera*)(camera)) -> farRange = farrange;
}

void CameraProjMode(TCamera camera, int projmode)
{
	((GameObject::_i_Camera*)(camera)) -> projMode = projmode;
}

void CameraZoom(TCamera camera, flt zoom)
{
	((GameObject::_i_Camera*)(camera)) -> zoom = zoom;
}

TVec3 CameraProject(TCamera camera, const TVec3 &position)
{
	//TODO:
	return Vec3 ( 0.0f );
}

TVec3 CameraUnproject(TCamera camera, const TVec3 &position)
{
	//TODO:
	return Vec3 ( 0.0f );
}

void GetCameraRange(TCamera camera, flt &nearRange, flt &farRange)
{
	nearRange = ((GameObject::_i_Camera*)(camera)) -> nearRange;
	farRange = ((GameObject::_i_Camera*)(camera)) -> farRange;
}

}